package com.zyf.spit.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyf.spit.pojo.Comment;
import com.zyf.spit.service.impl.CommentServiceImpl;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentServiceImpl commentService;

    /*
    新增评论
     */
@RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(Comment comment) {
        commentService.add(comment);
        return new Result(true, StatusCode.OK, "评论成功");
    }

    /*
    删除评论
     */
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public Result delete(String id) {
        commentService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    /*
    根据文章id查询评论列表
     */
    @RequestMapping(value = "/findContentByArticleId",method = RequestMethod.GET)
    public Result findContentByArticleId(String articleid, int pageNum, int pageSize) {
        List list = new ArrayList();
        list.add(commentService.findContentByArticleId(articleid, pageNum, pageSize));
        return new Result(true, StatusCode.OK, "查询成功", list);
    }
}
